package com.btex.app.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.btex.app.R;
import com.btex.app.entity.OTCBuyAndSellOrderBean;
import com.btex.app.tools.Tools;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * @author zy zhangyi <zhangyi, 1104745049@QQ.com
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/8/13
 * @time 下午3:29
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */

public class OTCSellAdapter extends BaseQuickAdapter<OTCBuyAndSellOrderBean.DataBean.BidsBean, BaseViewHolder> {

    private Context mContext;

    public OTCSellAdapter(@Nullable List<OTCBuyAndSellOrderBean.DataBean.BidsBean> data, Context context) {
        super(R.layout.otc_buy_item, data);
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, final OTCBuyAndSellOrderBean.DataBean.BidsBean item) {

        String type = item.getType();
        String danwei = item.getDanwei();
        ImageView otc_adapter_imag_bank_item = (ImageView) helper.getView(R.id.otc_adapter_imag_bank_item);//银行卡支付
        ImageView otc_adapter_imag_zhi_item = (ImageView) helper.getView(R.id.otc_adapter_imag_zhi_item);//支付宝支付
        ImageView otc_adapter_imag_wei_item = (ImageView) helper.getView(R.id.otc_adapter_imag_wei_item);//微信支付
        ImageView otc_adapter_imag_tyd_item = (ImageView) helper.getView(R.id.otc_adapter_imag_tyd_item);//天涯支付
        ImageView otc_adapter_imag_huiyuan_item = (ImageView) helper.getView(R.id.otc_adapter_imag_huiyuan_item);//商家标识
        TextView otc_adapter_text_name_item = (TextView) helper.getView(R.id.otc_adapter_text_name_item);//名字
        TextView otc_adapter_text_online_item = (TextView) helper.getView(R.id.otc_adapter_text_online_item);//是否在线
        TextView otc_adapter_text_cheng_jiao_item = (TextView) helper.getView(R.id.otc_adapter_text_cheng_jiao_item);//成交
        TextView otc_adapter_text_price_item = (TextView) helper.getView(R.id.otc_adapter_text_price_item);//价格
        TextView otc_adapter_text_number_item = (TextView) helper.getView(R.id.otc_adapter_text_number_item);//数量
        TextView otc_adapter_text_limit_item = (TextView) helper.getView(R.id.otc_adapter_text_limit_item);//限额
        TextView otc_adapter_text_price_item_type = (TextView) helper.getView(R.id.otc_adapter_text_price_item_type);

        otc_adapter_imag_huiyuan_item.setVisibility(View.GONE);

//        剩余数量
        otc_adapter_text_number_item.setText("剩余数量:" + item.getRest_num());

//        限额
        if ("USDT".equals(type)) {

            //剩余数量

            String s = Tools.round(Double.valueOf(item.getRest_num()), 4).toString();
            otc_adapter_text_number_item.setText("剩余数量:" + s + "\t" + type);
            otc_adapter_text_price_item_type.setText(danwei);
//            otc_adapter_text_limit_item.setText("限额:" + item.getMin_limit_total() + "~" + item.getMax_limit_total() + "\t" + "CNY");
            otc_adapter_text_limit_item.setText("限额:" + Tools.round(Double.valueOf(item.getMin_limit_total()), 2).toString().trim() + "~" + Tools.round(Double.valueOf(item.getMax_limit_total()), 2).toString().trim() + "\t" + danwei);
        } else {

            // 剩余数量

            String s = Tools.round(Double.valueOf(item.getRest_num()), 4).toString();
            otc_adapter_text_number_item.setText("剩余数量:" + s + "\t" + type);

            otc_adapter_text_price_item_type.setText(danwei);
//            otc_adapter_text_limit_item.setText("限额:" + item.getMin_limit_total() + "~" + item.getMax_limit_total() + "\t" + "TYZ");
            otc_adapter_text_limit_item.setText("限额:" + Tools.round(Double.valueOf(item.getMin_limit_total()), 2).toString().trim() + "~" + Tools.round(Double.valueOf(item.getMax_limit_total()), 4).toString().trim() + "\t" + danwei);
        }
//        姓名
        otc_adapter_text_name_item.setText(item.getTrue_name());
//        价格
        otc_adapter_text_price_item.setText(item.getPrice().substring(0, 4));
//        成交单数及平均用时
        otc_adapter_text_cheng_jiao_item.setText("成交单数" + item.getTrade_num() + "\t" + "\t" + "平均用时" + item.getAvg_time());
//        是否在线
        String online_time = item.getOnline_time();

        if ("1".equals(online_time)) {
            otc_adapter_text_online_item.setVisibility(View.VISIBLE);
        } else {
            otc_adapter_text_online_item.setVisibility(View.GONE);
        }

        List<String> pay_type = item.getPay_type();

        boolean alipay = pay_type.contains("alipay");
        boolean weixin = pay_type.contains("weixin");
        boolean bank = pay_type.contains("bank");
        boolean tianya = pay_type.contains("tianya");

        if (bank) {
            otc_adapter_imag_bank_item.setVisibility(View.VISIBLE);
        } else {
            otc_adapter_imag_bank_item.setVisibility(View.GONE);
        }

        if (weixin) {
            otc_adapter_imag_wei_item.setVisibility(View.VISIBLE);
        } else {
            otc_adapter_imag_wei_item.setVisibility(View.GONE);
        }

        if (alipay) {
            otc_adapter_imag_zhi_item.setVisibility(View.VISIBLE);
        } else {
            otc_adapter_imag_zhi_item.setVisibility(View.GONE);
        }


        if (tianya) {
            otc_adapter_imag_tyd_item.setVisibility(View.VISIBLE);
        } else {
            otc_adapter_imag_tyd_item.setVisibility(View.GONE);
        }


        Button button = (Button) helper.getView(R.id.otc_adapter_but_buy_item);
        button.setText("卖出");
        button.setTextColor(mContext.getResources().getColor(R.color.bg_red));
        button.setBackground(mContext.getResources().getDrawable(R.drawable.shape_otc_sell));
        helper.addOnClickListener(R.id.otc_adapter_but_buy_item);

    }
}
